package info.opensoaring.server.dao;

import javax.jdo.PersistenceManager;

public class BaseDaoJdo {

    protected PersistenceManager pm;

    protected BaseDaoJdo(PersistenceManager pm) {
	this.pm = pm;
    }

    protected void beginTx() {
	pm.currentTransaction().begin();
    }

    protected void commitTx() {
	pm.currentTransaction().commit();
    }

    protected void rollbackTx() {
	pm.currentTransaction().rollback();
    }

    protected void makePersistentInTx(Object o) {
	beginTx();
	try {
	    pm.makePersistent(o);
	    commitTx();
	} finally {
	    rollbackTx();
	}
    }

}
